#include <bits/stdc++.h>
#define int long long
using namespace std;

int months[] ={0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

// 字符串转 int
int s2i(string s) {
	int ans =0;
	for (const auto & c: s) { // 多使用 foreach
		ans = ans * 10 + (c-'0');
	}
	return ans;
}


// int 转 string
string i2s(int i){
	string ans;
	while (i) {
		ans += (i%10) + '0';
		i /= 10;
	}
	if (ans.size() < 2) ans += '0';
	// 字符串翻转一下
	reverse(ans.begin(), ans.end()); // 翻转时可以直接调用函数
	return ans;
}


bool isLeapYear(int year){
	return (year % 400 == 0) || (year%4==0 && year%100 != 0);
}

bool isreverse(string s) {
	for (int i=0; i < s.size()/2;i++) {
		if (s[i]!=s[s.size()-1-i]) return false; 
	}
	return true;
}

bool isABA(string s) {
	if (!isreverse(s)) {
		return false;
	}
	return (s[0]==s[2]) && (s[1]==s[3]); // ABABBABA 型
}


signed main()
{
	string s;
	cin >> s;
	int year = s2i(s.substr(0, 4));
	int month = s2i(s.substr(4, 2));
	int day = s2i(s.substr(6, 2));
	bool flag = false;
	for(int i=year; i<=9999;i++) {
		if (isLeapYear(i)) {
			months[2] = 29;
		}
		for (int j=1;j<=12;j++) {
			if (i==year&&j<month) continue; // 小于当前年的当前月直接跳过
			for (int k=1;k <= months[j];k++) {
				if (i==year&&j==month&&k<=day) continue; // 小于当天的直接跳过
				string sday = i2s(i) + i2s(j) + i2s(k);
				if (isreverse(sday) && !flag) {
					cout << sday << '\n';
					flag = true;
				}
				if (isABA(sday)) {
					cout << sday << '\n';
					return 0;
				}
			}
		}
	}
	return 0;
}
